import Vuex from "vuex"

export default new Vuex.Store({
    state: {
        user: null,
        isLogin: false,
        settingProject: {},
        settingProjectDialogVisible: false,
        addProjectDialogVisible: false,
        readMessageDialogVisible: false,
        readMessage: {},
        inviteMessages: [],
        notifyMessages: [],
        privateMessages: [],
        showingMessage: {},
        msgCount: 0,
        addMockDialogVisible: false,
        addMock: {
            name: '',
            path: '',
            method: 'GET',
            template: '',
            responseCode: 200,
            responseHeaders: []
        },
        mocks: [
            {
                id: '1712848020383023105',
                name: '123',
                path: '/123',
                method: 'GET',
            }
        ],
        planeTabIsModified: [false, false, false],
        needRemoveTabId: '',
        sharedWorker: null,
    },
    mutations: {
        saveUserData(state, userData) {
            localStorage.setItem("userData", JSON.stringify(userData))
            state.user = userData;
            state.isLogin = userData !== null && Object.keys(userData).length > 0;
        },
        clearAllUserData(state) {
            localStorage.removeItem("token")
            localStorage.removeItem("userData")
            state.user = null
            state.isLogin = false
            if (state.sharedWorker) {
                state.sharedWorker.port.postMessage({
                    type: 'closeWebSocket'
                })
            }
        },
    }
})